package com.mineoj.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mineoj.model.entity.Post;
import com.mineoj.model.entity.Question;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
* @author 明月
* @description 针对表【question(题目)】的数据库操作Mapper
* @createDate 2025-04-01 16:05:13
* @Entity com.mineoj.model.entity.Question
*/
public interface QuestionMapper extends BaseMapper<Question> {


    /**
     * 热门问题查询（综合多个热度指标）
     */
    @Select("SELECT *, " +
            "(thumbNum * 0.4 + favourNum * 0.3 + (acceptedNum / submitNum) * 0.3) AS hot_score " +
            "FROM question " +
            "WHERE isDelete = 0 AND submitNum > 50 " +
            "ORDER BY hot_score DESC " +
            "LIMIT #{limit}")
    List<Question> selectHotQuestions(@Param("limit") int limit);

    /**
     * 更新提交数和通过数
     */
    @Update("UPDATE question SET " +
            "submitNum = submitNum + #{submitIncr}, " +
            "acceptedNum = acceptedNum + #{acceptIncr} " +
            "WHERE id = #{id} AND isDelete = 0")
    int updateSubmitCount(@Param("id") Long id,
                          @Param("submitIncr") Integer submitIncr,
                          @Param("acceptIncr") Integer acceptIncr);
}




